package com.shoukaiseki.test.spring.springbootdemo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;

@Controller
@EnableAutoConfiguration
public class EurekaserverdemoApplication {

    @Value("${person.name}")
    private String name="梅西";

    @RequestMapping("/")
    @ResponseBody
    String home() {
        Yaml yaml=new Yaml();
        StringBuffer yamlSB=new StringBuffer();
        System.out.println("------------");
        try {
            HashMap<String,Object> obj=yaml.loadAs(new ClassPathResource("application.yml").getInputStream(),HashMap.class);

            if(obj!=null){
                for (String key:obj.keySet() ) {
                    yamlSB.append(key);
                    yamlSB.append("=");
                    yamlSB.append(obj.get(key));
                    yamlSB.append("<br>");

                }

            }

            System.out.println("obj="+obj);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "Hello "+name+"!" +
                "<br>"+
                yamlSB.toString();
    }

    public static void main(String[] args) {
        SpringApplication.run(EurekaserverdemoApplication.class, args);
    }
}
